home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / newlooklib.lha / newlook / test.c < prev    next >
C/C++ Source or Header  |  1993-11-07  |  6KB  |  246 lines

  1. /*
  2.  *  NewLook's TEST.C
  3.  */
  4.  
  5. #include <exec/types.h>
  6. #include <exec/memory.h>
  7. #include <intuition/intuition.h>
  8. #include <graphics/gfx.h>
  9. #include <graphics/gfxbase.h>
  10. #include <graphics/rastport.h>
  11.  
  12. #include "newlook.h"
  13.  
  14. extern VOID DrawBorder( struct RastPort *, struct Border *, WORD, WORD );
  15.  
  16. #ifndef AUTOSCROLL
  17. #define AUTOSCROLL 0x4000  /* V36+ */
  18. #endif
  19.  
  20. /* The NewWindow Flags and IDCMPFlags */
  21.  
  22. #define NW_FLAGS  (WINDOWCLOSE|WINDOWDEPTH|WINDOWSIZING|WINDOWDRAG|ACTIVATE| \
  23.                    SMART_REFRESH|RMBTRAP)
  24.  
  25. #define NW_IDCMP  (CLOSEWINDOW|GADGETUP|VANILLAKEY)
  26.  
  27. struct Window *w= (struct Window *)NULL;
  28. struct Gadget *b0, *b1, *b2;
  29.  
  30. const ULONG MyNewLookHandle= 42L;
  31.  
  32. STRPTR CycleTexts[]= { "Cycle",
  33.                        "Saikel",
  34.                        "Zeigel",
  35.                        NULL
  36.                      };
  37.  
  38. STRPTR ListViewTexts[]= { "This",
  39.                           "is a selfmade",
  40.                           "ListView",
  41.                           "Gadget",
  42.                           NULL
  43.                         };
  44.  
  45. char *whichwitch= "r";
  46. struct ScalebarInfo *si;
  47. long sN= 0;
  48.  
  49. void closeit()
  50. {
  51.   if(w)
  52.   { CloseWindow(w);
  53.     w= (struct Window *)NULL;
  54.   }
  55.   SmartFreeAll(MyNewLookHandle);
  56.  
  57.   /* just to be sure... */
  58.   /*SmartFreeAll(MAGIC_HANDLE);*/
  59. }
  60.  
  61. int openit()
  62. {
  63.   struct NewWindow *nw;
  64.   struct Gadget *glist;
  65.  
  66.   (void)SetNewLookHandle(MyNewLookHandle);
  67.  
  68.   /* create gadgets */
  69.   { struct Gadget *g;
  70.     if( g= CreateButton(20,20,80,15,"_Button",0x0B) )
  71.     { glist= g;
  72.       g->Activation |= TOGGLESELECT;
  73.       b0= g;
  74.       g->NextGadget= CreateButton(120,20,80,15,"nottuB",0x0D);
  75.       if(g= g->NextGadget)
  76.       { b1= g;
  77.         g->Flags= GADGHBOX;
  78.         (void)AddGText(g,NULL,"depends on Button state");
  79.         g->NextGadget= CreateCheckbox(50,50,TRUE,0x0C);
  80.         if(g= g->NextGadget)
  81.         { (void)AddGText(g,NULL,"CheckBox");
  82.           g->NextGadget= CreateStrGadget(100,80,80, 30,0x05);
  83.           if(g= g->NextGadget)
  84.           { (void)AddGText(b2=g,"StrGadget","w/ text on both sides");
  85.             g->NextGadget= CreateButton(50,100,200,50,"Big Button",0xBB);
  86.             if(g= g->NextGadget)
  87.             { (void)AddGText(g,"Left","Right");
  88.               g->NextGadget= CreateCycleButton(200,50,80,CycleTexts,0x00);
  89.               if(g= g->NextGadget)
  90.               { g->NextGadget= CreateSlider(50,160,90, whichwitch, 100);
  91.                 if(g= LastGadget(g))
  92.                 { g->NextGadget= CreateRadioButton(290,40,FALSE,42);
  93.                   if(g= g->NextGadget)
  94.                   { (void)AddGText(g,NULL,"Radi_oButt_on");
  95.                     g->NextGadget= CreateListView(330,100, 15, 7, ListViewTexts,1000);
  96.                     if(g= LastGadget(g))
  97.                     { g->NextGadget= CreatePaletteButton(450,20, 26,11, 3, 123);
  98.                       if(g= g->NextGadget)
  99.                       {
  100.                         ; /* be happy */
  101.                       }
  102.                       else return 11;
  103.                     }
  104.                     else return 10;
  105.                   }
  106.                   else return 9;
  107.                 }
  108.                 else return 8;
  109.               }
  110.               else return 7;
  111.             }
  112.             else return 6;
  113.           }
  114.           else return 5;
  115.         }
  116.         else return 4;
  117.       }
  118.       else return 3;
  119.     }
  120.     else return 2;
  121.   }
  122.  
  123.   if(nw= InitNewWindow(0L,"NewLook",600,220,NW_IDCMP,NW_FLAGS,glist))
  124.   {
  125.     /* open our window */
  126.     w= (struct Window *)OpenWindow(nw);
  127.   }
  128.  
  129.   if(!w)
  130.     return 1;
  131.  
  132.   { struct Border *b= CreateFrame(0,0,400,50,10,5);
  133.     if(b)
  134.       DrawBorder(w->RPort,b,10,180);
  135.     /* else panic! */
  136.   }
  137.  
  138.   SetScalebar(w, si= CreateScalebar(300,60, 200,13, -100,200), sN);
  139.  
  140.   RefreshWindowFrame(w);
  141.   return 0;
  142. }
  143.  
  144. int handleit()
  145. {
  146.   int running= 1;
  147.   struct IntuiMessage *imsg;
  148.   ULONG class;
  149.   USHORT code;
  150.   struct Gadget *g;
  151.  
  152.   Wait(1L << w->UserPort->mp_SigBit);
  153.  
  154.   while(imsg=(struct IntuiMessage *)GetMsg(w->UserPort))
  155.   { class = imsg->Class;
  156.     code  = imsg->Code;
  157.     g     = (struct Gadget *)imsg->IAddress;
  158.     ReplyMsg(imsg);
  159.  
  160.     switch(class)
  161.     {
  162.       case CLOSEWINDOW:
  163.         printf("CLOSEWINDOW\n");
  164.         running= 0;
  165.         break;
  166.  
  167.       case VANILLAKEY:
  168.         switch( (UBYTE)code )
  169.         {
  170.           case '\33': /* ESC */
  171.             running= 0;
  172.             break;
  173.           default:
  174.             printf("VANILLAKEY: %d\n",code);
  175.             break;
  176.         }
  177.         break;
  178.  
  179.       case GADGETUP:
  180.         printf("GADGETUP: %d\n",g->GadgetID);
  181.  
  182.         switch( g->GadgetID )
  183.         {
  184.           case 0x0B:  /* Button */
  185.             if(g->Flags & SELECTED)
  186.               SetGFlags(w,b1, b1->Flags | SELECTED);
  187.             else
  188.               SetGFlags(w,b1, b1->Flags &~ SELECTED);
  189.             break;
  190.           case 0x0C:  /* Checkbox */
  191.             if(g->Flags & SELECTED)
  192.             { OnGadgetSafely(w,b0);
  193.               OnGadgetSafely(w,b2);
  194.             }
  195.             else
  196.             { OffGadgetSafely(w,b0);
  197.               OffGadgetSafely(w,b2);
  198.             }
  199.             break;
  200.           case 0x05: /* StringGadget */
  201.             SetScalebar(w, si,sN=atol(((struct StringInfo *)(g->SpecialInfo))->Buffer));
  202.             break;
  203.           case 0xBB:
  204.             { long n;
  205.               for(n=sN; n<250; SetScalebar(w, si,n++)) WaitTOF();
  206.               for(n=250; n>-150; SetScalebar(w, si,--n)) WaitTOF();
  207.               for(n=-150; n<sN; SetScalebar(w, si,n++)) WaitTOF();
  208.             }
  209.             break;
  210.           case 0x00:
  211.             DoCycleButton(w,g);
  212.             /* CycleButton's UserData is NewLook private! */
  213.             break;
  214.         }
  215.         break;
  216.     }
  217.   }
  218.   return running;
  219. }
  220.  
  221. #ifdef DEBUG
  222. extern void DebugSmartMemList(void);
  223. #endif
  224.  
  225. main(int ac, char **av)
  226. {
  227.   if(ac>1)
  228.     whichwitch= av[1];
  229.  
  230.   if( openit() == 0 )
  231.   {
  232. #ifdef DEBUG
  233.     printf("Memory allocated via SmartAllocate()\n");
  234.     DebugSmartMemList();
  235. #endif
  236.     while( handleit() );
  237.  
  238.     closeit();
  239. #ifdef DEBUG
  240.     printf("\nSmartMem's Memory list at exit\n");
  241.     DebugSmartMemList();
  242. #endif
  243.   }
  244.   exit(0);
  245. }
  246.